#include "tabwidget.h"
#include "TabWidget/configtabwidget.h"
#include "TabWidget/infotabwidget.h"

#include <QLabel>
#include <QPlainTextEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QDebug>

TabWidget::TabWidget(QWidget *parent)
    : QWidget{parent}
{
    m_tabWidget.setParent(this);
    m_tabWidget.resize(1800,1000);

    m_tabWidget.setTabPosition(QTabWidget::North);
    m_tabWidget.setTabShape(QTabWidget::Rounded);
    m_tabWidget.setTabsClosable(false);

    ConfigTabWidget* configTabWidget = new ConfigTabWidget(&m_tabWidget);
    m_tabWidget.addTab(configTabWidget, "配置");


    InfoTabWidget* infoTabWidget = new InfoTabWidget(&m_tabWidget);
    m_tabWidget.addTab(infoTabWidget, "信息");

    QWidget* checkWidget = new QWidget(&m_tabWidget);
    QHBoxLayout* checkLayout = new QHBoxLayout(this);
    QLabel* lb3 = new QLabel(checkWidget);
    lb3->setText("页面3");
    lb3->setAlignment(Qt::AlignCenter);
    checkLayout->addWidget(lb3);
    checkWidget->setLayout(checkLayout);
    m_tabWidget.addTab(checkWidget, "校准");

    QWidget* parameterWidget = new QWidget(&m_tabWidget);
    QHBoxLayout* parameterLayout = new QHBoxLayout(this);
    QLabel* lb4 = new QLabel(parameterWidget);
    lb4->setText("页面4");
    lb4->setAlignment(Qt::AlignCenter);
    parameterLayout->addWidget(lb4);
    parameterWidget->setLayout(parameterLayout);
    m_tabWidget.addTab(parameterWidget, "参数");

    m_tabWidget.setCurrentIndex(0);

    connect(&m_tabWidget,SIGNAL(currentChanged(int)),this,SLOT(onTabCurrentChanged(int)));
    connect(&m_tabWidget,SIGNAL(tabCloseRequested(int)),this,SLOT(onTabCloseRequested(int)));
}

void TabWidget::onTabCurrentChanged(int index)
{
    qDebug()<<"Page change to:"<<index;
}

void TabWidget::onTabCloseRequested(int index)
{
    m_tabWidget.removeTab(index);
}
